FROM docker.m.daocloud.io/node:18.17-alpine as build-stage

WORKDIR /app

# 设置 npm 镜像源
RUN npm config set registry https://registry.npmmirror.com/

# 复制依赖文件
COPY package*.json ./

# 安装依赖并设置权限
RUN npm ci --quiet && \
    chmod -R 777 /app/node_modules/.bin/

# 复制其他源代码
COPY . .

# 设置权限并构建
RUN chmod -R 777 /app && \
    chmod +x /app/node_modules/.bin/vite && \
    npm run build

FROM docker.m.daocloud.io/nginx:alpine as production-stage
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]